$("#submit1").on('click',function () {
    if($("#username").val() == '') {
        $(".tips").html('老兄！！你用户名呢！？？？');
        $("#logo").css({"width":"72px"});
        $("#logo").attr("src",'static/images/login/null-password.jpg')
    } else if($("#password").val() == '') {
        $(".tips").html('老兄！！你密码呢！？？？');
        $("#logo").css({"width":"72px"});
        $("#logo").attr("src",'static/images/login/null-password.jpg')
    } else {
        $.post("/wechat/bind",{username:$("#username").val(),password:$("#password").val()},
            function (result) {
                if(result.success){
                    layer.open({
                        title: '绑定成功'
                        ,content: '<span>恭喜您绑定成功,<br/>5s后自动跳转</span>'
                        ,closeBtn: 0
                        ,success: function(layero, index){
                            console.log(layero, index);
                            setTimeout(jump, 1000 * 5);
                            function jump() {
                                window.location.href = "/main";
                            }
                        }
                        ,anim:1
                        ,closeBtn: 1
                        ,btn:'确认'
                        ,yes: function(index, layero){
                            window.location.href = "/main";
                            layer.close(index);
                        }
                    });
                }else{
                    $("#username").val("");
                    $("#password").val("");
                    $(".tips").html(result.msg);
                }
        })
    }
})




$(function () {
    var myForm =$(".validform").Validform({
        tiptype:3,
        postonce:true,
        usePlugin:{
            passwordstrength:{
                minLen:6,
                maxLen:15,
                trigger:function(obj,error){
                    if(error){
                        $("#valick").show();
                        $(".passwordStrength").hide();
                    }else{
                        $("#valick").hide();
                        $(".passwordStrength").show();
                    }
                }
            }
        },
        callback:function(data){
            let serializeObject = data.serializeObject();
            $.post("/wechat/register",serializeObject,function (result) {
                console.debug(result);
                if(result.success){
                    layer.open({
                        title: '注册成功'
                        ,closeBtn: 0
                        ,content: '<span>恭喜您注册成功,<br/>5s后自动跳转</span>'
                        ,success: function(layero, index){
                            console.log(layero, index);
                            setTimeout(jump, 1000 * 5);
                            function jump() {
                                window.location.href="/main";
                            }
                        }
                        ,anim:1
                        ,closeBtn: 1
                        ,btn:'确认'
                        ,yes: function(index, layero){
                            window.location.href="/main";
                            layer.close(index);
                        }
                    });
                }else{
                    myForm.eq(0).resetForm();
                    $(".passwordStrength").hide();
                    $(".regtips").html(result.msg);
                }
            });
            return false;
        }
    });
});

$(function () {
    $(document.documentElement).on("keydown", function (e) {
        if(e.keyCode==13){
            if($(".login").css("opacity")=="1"){
                $("#submit1").click();
            }else if($(".regis").css("opacity")=="1"){
                $("#submit2").click();
            }
        }
    });
});



$("#regisbtn_login").on('click',function () {
    $(".regis").css({
        "left":"0px",
        "opacity":"1"
    });
    $(".login").css({
        "left":"-404px",
        "opacity":"0",
    });
})
$("#regisbtn_msg").on('click',function () {
    $(".regis").css({
        "left":"0px",
        "opacity":"1"
    });
    $(".msglogin").css({
        "left":"-404px",
        "opacity":"0",
    });
})
$("#loginbtn_regis").on('click',function () {
    $(".login").css({
        "left":"0px",
        "opacity":"1",
    });
    $(".regis").css({
        "left":"404px",
        "opacity":"0"
    });
})
$("#loginbtn_msg").on('click',function () {
    $(".msglogin").css({
        "left":"-404px",
        "opacity":"0",
    });
    $(".login").css({
        "left":"0px",
        "opacity":"1",
    });
})
$("#msgbtn_login").on('click',function () {
    $(".login").css({
        "left":"404px",
        "opacity":"0",
    });
    $(".msglogin").css({
        "left":"0px",
        "opacity":"1",
    });
})
$("#msgbtn_regis").on('click',function () {
    $(".regis").css({
        "left":"404px",
        "opacity":"0"
    });
    $(".msglogin").css({
        "left":"0px",
        "opacity":"1",
    });
})
